fix Arbitrary file write extracting an archive containing symbolic links on artifacts() lead to Path Traversal#430
Closed
odaysec wants to merge 1 commit intooasisprotocol:masterfrom
odaysec:patch-1
Closed
fix Arbitrary file write extracting an archive containing symbolic links on artifacts() lead to Path Traversal#430odaysec wants to merge 1 commit intooasisprotocol:masterfrom odaysec:patch-1
odaysec wants to merge 1 commit intooasisprotocol:masterfrom
odaysec:patch-1
Conversation
✅ Deploy Preview for oasisprotocol-cli canceled.
|
Member
|
Thanks for bringing this up! An improved version of the PR which works for our use case where root filesystem templates are the things being extracted (and we cannot just forbid such symlinks) is in #572. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cli/cmd/rofl/build/artifacts.go
Line 185 in c6de32e
To fix the issue need to ensure that symbolic links are resolved and validated before creating them. This involves:
filepath.EvalSymlinksto resolve any symbolic links in theheader.Linknamepath.tar.TypeSymlinkcase to incorporate these checks.The fix will ensure that symbolic links cannot be used to write files outside the intended directory, mitigating the vulnerability.
Extracting symbolic links from a malicious zip archive, without validating that the destination file path is within the destination directory, can cause files outside the destination directory to be overwritten. This can happen if there are previously-extracted symbolic links or directory traversal elements and links (
..) in archive paths. This problem is related to the ZipSlip vulnerability which is detected by thego/zipslipquery; please see that query's help for more general information about malicious archive file vulnerabilities. This query considers the specific case where symbolic links are extracted from an archive, in which case the extraction code must be aware of existing symbolic links when checking whether it is about to extract a link pointing to a location outside the target extraction directory.POC
links are extracted from an archive using the syntactic
filepath.Relfunction to check whether the link and its target fall within the destination directory. However, the extraction code doesn't resolve previously-extracted links, so a pair of links likesubdir/parent -> ..followed byescape -> subdir/parent/.. -> subdir/../..leaves a link pointing to the parent of the archive root. The syntacticRelis ineffective because it equatessubdir/parent/..withsubdir/, but this is not the case whensubdir/parentis a symbolic link.To fix this vulnerability, resolve pre-existing symbolic links before checking that the link's target is acceptable:
References
Zip Slip Vulnerability
Path Traversal
CWE-22